package com.huluobo.a2204kotlinshopping.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import androidx.constraintlayout.widget.ConstraintLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2204kotlinshopping.R
import com.huluobo.base.bean.CategoryBean

/**
 *  Created by LC on 2024/7/27.
 */
class CategoryParentAdapter(list: MutableList<CategoryBean>) :
    BaseQuickAdapter<CategoryBean, BaseViewHolder>(R.layout.item_category_parent, list) {

    //一级列表的第0位,初始化的时候需要用到,因为第0位的item的id就是1
    private var selectItemId = 1
    override fun convert(helper: BaseViewHolder, item: CategoryBean) {
        helper.setText(R.id.item_category_parent_tv, item.category_name)

        helper.getView<ConstraintLayout>(R.id.item_category_parent_cl).background =
            if (item.id == selectItemId) ColorDrawable(Color.LTGRAY) else null
    }

    fun setSelectItemId(itemId: Int) {
        selectItemId = itemId
        notifyDataSetChanged()
    }
}